<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // //数组解构的默认值
        // const [a, b] = [];
        // console.log(a, b); //undefined undefined

        //const [a = 1, b = 2] = [];
        //console.log(a, b); //1  2


        //默认值的生效条件
        //只有当一个数组成员严格等于(===)undefined时，对应的默认值才会生效
        //const [a = 1, b = 2] = [3, 0]; //3 0
        // const [a = 1, b = 2] = [3, null]; //3 null
        //  const [a = 1, b = 2] = [3]; //3,2
        //  console.log(a, b);


        //默认值表达式
        //如果默认值是表达式  默认值表达式是惰性求值的

        const fun = () => {

            console.log("我被执行了");
            return 2;
        }
        const [x = fun()] = [1];
        console.log(x); //1

        //数组的解构赋值的应用
        function fun() {
            console.log(arguments);
        }
        fun(1, 2)

        //函数参数的解构赋值
        const array = [1, 2];

        const add = ([x, y]) => x + y;
        console.log(add(array));
    </script>
</body>

</html>